package com.hc.service.impl;

import com.hc.entity.RoleAuth;
import java.util.List;
import com.github.pagehelper.PageHelper;
import com.hc.service.RoleAuthService;
import com.hc.dao.RoleAuthDao;
import com.hc.utils.PageBean;
import com.hc.utils.PageParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleAuthServiceImpl implements RoleAuthService {

    @Autowired
    private RoleAuthDao roleAuthDao;

    @Override
    public int addRoleAuth(RoleAuth roleAuth){
        int res = roleAuthDao.insertRoleAuth(roleAuth);
        return res;
    }

    @Override
    public int addRoleAuthSelective(RoleAuth roleAuth){
        int res = roleAuthDao.insertRoleAuthSelective(roleAuth);
        return res;
    }

	@Override
    public int batchAddRoleAuth(List<RoleAuth> roleAuthList){
		int res = roleAuthDao.batchInsertRoleAuth(roleAuthList);
		return res;
	}

    @Override
    public int deleteRoleAuthById(Integer id){
        int res = roleAuthDao.deleteRoleAuthById(id);
        return res;
    }
    
 	@Override
	public int deleteRoleAuthByCondition(RoleAuth roleAuth){
	 	int res = roleAuthDao.deleteRoleAuthByCondition(roleAuth);
        return res;
	}
	
	@Override
	public int batchDeleteRoleAuthByIdList(List<Integer> idList){
		int res = roleAuthDao.batchDeleteRoleAuthByIdList(idList);
        return res;
	}
	
    @Override
    public int updateRoleAuth(RoleAuth roleAuth){
        int res = roleAuthDao.updateRoleAuth(roleAuth);
        return res;
    }

    @Override
    public int updateRoleAuthSelective(RoleAuth roleAuth){
        int res = roleAuthDao.updateRoleAuthSelective(roleAuth);
        return res;
    }

    @Override
    public long getCount(){
        long res = roleAuthDao.selectCount();
        return res;
    }

    @Override
    public long getCountByCondition(RoleAuth roleAuth){
        long res = roleAuthDao.selectCountByCondition(roleAuth);
        return res;
    }

    @Override
    public RoleAuth getRoleAuthById(Integer id){
        RoleAuth res = roleAuthDao.selectRoleAuthById(id);
        return res;
    }

    @Override
    public List<RoleAuth> getAllRoleAuth(){
        List<RoleAuth> res = roleAuthDao.selectAllRoleAuth();
        return res;
    }

	@Override
	public 	List<RoleAuth> getRoleAuthByCondition(RoleAuth roleAuth){
		List<RoleAuth> res = roleAuthDao.selectRoleAuthByCondition(roleAuth);
		return res;
	}
	
    @Override
    public PageBean<RoleAuth> getRoleAuthWithPagination(PageParam pageParam){
        long count = roleAuthDao.selectCount();
        PageBean<RoleAuth> pageBean = new PageBean<>(pageParam, (int)count);
        pageBean.setPageNum(pageParam.getPage());
        PageHelper.startPage(pageParam.getPage(),pageParam.getRows());
        List<RoleAuth> data = roleAuthDao.selectAllRoleAuth();
        pageBean.setRecords(data);
        return pageBean;
    }

	@Override
	public PageBean<RoleAuth> getRoleAuthWithPaginationByCondition(PageParam pageParam, RoleAuth roleAuth){
        long count = roleAuthDao.selectCountByCondition(roleAuth);
        PageBean<RoleAuth> pageBean = new PageBean<>(pageParam, (int)count);
        pageBean.setPageNum(pageParam.getPage());
        PageHelper.startPage(pageParam.getPage(),pageParam.getRows());
		List<RoleAuth> data = roleAuthDao.selectRoleAuthByCondition(roleAuth);
		pageBean.setRecords(data);
        return pageBean;
	}

    //////////////////////////// 外键相关 /////////////////////////////////////
    @Override
    public List<RoleAuth> getRoleAuthByRole(Integer role){
        List<RoleAuth> res = roleAuthDao.selectRoleAuthByRole(role);
        return res;
    }

    //////////////////////////// 外键相关 /////////////////////////////////////
    @Override
    public List<RoleAuth> getRoleAuthByAuth(Integer auth){
        List<RoleAuth> res = roleAuthDao.selectRoleAuthByAuth(auth);
        return res;
    }

}